#!/usr/bin/env python
# -*- coding: utf-8 -*-
#

import time

from celtuce.event import Event,OP_INSERT,OP_ERASE,OP_FIND, OP_TEST_ECHO

import celtuce.yaml as yaml

encode = yaml.dump
decode = yaml.load

from celtuce.help import logging

logger = logging.getLogger('codec.yaml')


request = Event()
request.op = OP_TEST_ECHO
request.body = ('test.codec', 'codec-key', 'x' * 100, int(time.time() * 1000))
request.request_id = 'yaml.1234567890'

encoded = encode( request )
logger.info('ENCODED : %s', encoded)

# test codec performance
time_start = time.time()
times = 10000
for i in xrange(times) :
    encoded = encode( request )
    decoded = decode( encoded )
    assert request == decoded
time_last = time.time() - time_start    
tps = times / time_last
logger.info('test yaml-codec %d times last %.2f seconds, tps=%.2f', times, time_last, tps)


